#!/bin/bash
 
# 更新系统
yum update -y
 
# 安装vsftpd
yum install -y vsftpd
 
# 启动并设置开机自启动
systemctl start vsftpd
systemctl enable vsftpd
 
# 添加用户ftpuser并设置密码
adduser ftpuser
echo 'ftpuser:YOUR_PASSWORD' | chpasswd
 
# 创建FTP目录并设置权限
mkdir /home/ftpuser/ftp
chown -R ftpuser:ftpuser /home/ftpuser/ftp
chmod -R 755 /home/ftpuser
 
# 修改vsftpd配置
cp /etc/vsftpd/vsftpd.conf /etc/vsftpd/vsftpd.conf.orig
echo "
anonymous_enable=NO
local_enable=YES
write_enable=YES
local_umask=022
dirmessage_enable=YES
xferlog_enable=YES
connect_from_port_20=YES
xferlog_std_format=YES
ascii_upload_enable=YES
ascii_download_enable=YES
ftp_data_port=20
listen=YES
pam_service_name=vsftpd
userlist_enable=YES
tcp_wrappers=YES
user_sub_token=$USER
local_root=/home/$USER/ftp
" > /etc/vsftpd/vsftpd.conf
 
# 重启vsftpd服务
systemctl restart vsftpd
 
# 设置防火墙允许FTP服务
firewall-cmd --zone=public --add-service=ftp --permanent
firewall-cmd --reload
 
echo "FTP server setup complete. You can login with ftpuser and YOUR_PASSWORD."
